import { Promise } from 'drunk-base';
import { IStandarPageModel } from './PageModel';
import { HOST } from '../../../../service/Config';
import { getJsonWithToken, deleteJsonWithToken, putJsonWithToken, postJsonWithToken } from '../../../../service/HttpClient';
import { IPageMetaData } from "../../../ListModel";

export function getPage(id: string): Promise<IStandarPageModel> {
    return getJsonWithToken(`${HOST}/content/standard/pages/${id}`);
}

export function getPageList(page: number = 0, pageSize: number = 20): Promise<{ meta: IPageMetaData; data: IStandarPageModel[] }> {
    return getJsonWithToken(`${HOST}/content/standard/pages?page=${page}&size=${pageSize}`);
}

export function createPage(data: IStandarPageModel): Promise<IStandarPageModel> {
    return postJsonWithToken(`${HOST}/content/standard/pages`, data);
}

export function updatePage(id: string, data: IStandarPageModel): Promise<IStandarPageModel> {
    return putJsonWithToken(`${HOST}/content/standard/pages/${id}`, data);
}

export function deletePage(id: string) {
    return deleteJsonWithToken(`${HOST}/content/standard/pages/${id}`);
}

export function search(name: string, startTime: number, endTime: number, page = 0, size = 20): Promise<{ data: IStandarPageModel[], meta: IPageMetaData }> {
    return getJsonWithToken(`${HOST}/content/standard/pages?title=${name}&startTime=${startTime}&endTime=${endTime}&page=${page}&size=${size}`);
}
